/**
 * 
 */
package com.cares.core.base.controller;

/**   
 * @作者 Stone
 * @创建日期 2013-6-18 下午01:51:59
 * @版本 V1.0
 * @类说明
 */
/**
 * @author Administrator
 *
 */

import java.io.IOException;
import java.io.PrintWriter;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.MessageSource;

public class BaseController {
	public static final String AJAX_MESSAGE = "success";
	public static final String ERR_MESSAGE = "err_msg";
	public static final String SUCCESS = "true";
	public static final String FAIL = "fail";
	public static final String SUCCESS_PAGE = "frm/page/success";
	
	public static final String SUCCESS_BACKTOURL="backToUrl";
	public static final String SUCCESS_CALLJS="callJS";
	public static final String SUCCESS_MSG="infoMsg";
	protected Logger logger = LoggerFactory.getLogger(getClass());

	public void debug(String message) {
		logger.debug(message);
	}

	public void error(String message) {
		logger.error(message);
	}

	public void info(String message) {
		logger.info(message);
	}

	public void renderText(HttpServletResponse response, String result)
			throws IOException {
		PrintWriter out = response.getWriter();
		response.setHeader("Cache-Control", "no-store");
		response.setHeader("Pragma", "no-cache");
		response.setDateHeader("Expires", 0);
		if (null == result)
			out.print("");
		else
			out.print(result);
		out.flush();
		out.close();
	}

	public void outString(HttpServletResponse response, String str) {
		try {
			PrintWriter out = response.getWriter();
			out.write(str);
			out.flush();
			out.close();
			logger.info("OUT FLASH STRING>>" + str);
		} catch (IOException e) {
		}
	}

	private MessageSource messageSource;

	@Resource(name = "messageSource")
	public void setMessageSource(MessageSource messageSource) {
		this.messageSource = messageSource;
	}

	public String getMessage(String key) {
		return this.messageSource.getMessage(key, null, null);
	}
}
